//--------------------------------------------------------------------------------
// This file is a portion of the D2D1Renderer.  It is distributed
// under the MIT License, available in the root of this distribution and 
// at the following URL:
//
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) Mirco Timmermann
//
// Sources: http://www.liranuna.com/implementing-eventdispatcher-in-cpp/
//--------------------------------------------------------------------------------
#pragma once

#ifndef _EVENTDISPATCHER_H
#define _EVENTDISPATCHER_H

#include "Event.h"
#include <string>
#include <map>
#include <list>
#include <algorithm>

#include <functional>

typedef std::function<void(const Event &)> FunctionPtr;

class EventDispatcher {

public:
	void addEventListener(const std::string &type, FunctionPtr listener, bool useCapture = false, int priority = 0, bool useWeakReference = false);
	void removeEventListener(const std::string &type, FunctionPtr listener, bool useCapture = false);

	bool hasEventListener(const std::string &type);
	void dispatchEvent(const Event &event);

private:
	std::map<const std::string, std::map<int, std::list<FunctionPtr>>> eventHandlerList;
};

#endif